//
//  Course_ViewController.m
//  YUXiu
//
//  Created by 王竞成 on 16/6/22.
//  Copyright © 2016年 Wang. All rights reserved.
//

#import "Course_ViewController.h"
#import "OL_View.h"
#import "courseModel.h"
#import "CourceHomeCell.h"
#import "PlayerViewController.h"

@interface Course_ViewController ()<UIScrollViewDelegate>{
    courseModel *cModel;
    UIScrollView *headScroll;
    NSArray *dataArr;
}
@property(nonatomic,strong)NSArray *headArr;
@end

@implementation Course_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setTranslucent:NO];
    
    
}
-(void)autoConfigViews{
    dataArr = @[@"减脂瑜珈",@"瑜珈塑形"];
    cModel = [[courseModel alloc]init];
    cModel.titleStr = @"廋腿瑜珈姿势";
    cModel.courseStr = @"课程";
    cModel.fanStr = @"9.9万人学习";
    _headArr = @[cModel,cModel,cModel];
    
    headScroll = [[UIScrollView alloc]initWithFrame:krect(0, 0, kScreenWidth, 140)];
    headScroll.contentSize = CGSizeMake(_headArr.count*190, 140) ;
    headScroll.showsHorizontalScrollIndicator = NO;
//    headScroll.pagingEnabled = YES;
    headScroll.delegate = self;

    for (int i = 0; i<_headArr.count; i++) {
        OL_View *headerCourse = [[OL_View alloc]initWithFrame:krect(5 + i*185, 20, 180, 120) model:_headArr[i]];
        [headScroll addSubview:headerCourse];

    }
    [self.tableView setTableHeaderView:headScroll];
}
//点击scroView
- (void)ScrollViewclickToWeb:(UIButton*)scrollBtn {
   //这里预留scrollview上的各个课程添加手势后的点击事件
    
}
#pragma mark - tableView Delegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"courseCell";
    CourceHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell) {
        
        cell = [[CourceHomeCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify Model:cModel];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    if (indexPath.row == 0) {
        [cell.memberShare setHidden:YES];
        cell.priceLabel.text = @"50钻";
    }
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headV = [[UIView alloc]initWithFrame:krect(0, 0, kScreenWidth, 40)];
    UIButton *titleBtn = [[UIButton alloc]initWithFrame:krect(0, 10, 120, 20)];
    [titleBtn setTitle:dataArr[section] forState:UIControlStateNormal];
    [titleBtn setTitleColor:kBlackCOLOR forState:UIControlStateNormal];
    [titleBtn setImage:[UIImage imageNamed:@"navigationbar_Personal_normal"] forState:UIControlStateNormal];
    titleBtn.enabled = NO;
    [headV addSubview:titleBtn];
    
    UIButton *moreBtn = [[UIButton alloc]initWithFrame:krect(kScreenWidth-70, 10, 60, 20)];
    [moreBtn setTitle:@"更多" forState:UIControlStateNormal];
    [moreBtn setTitleColor:kLightGrayCOLOR forState:UIControlStateNormal];

    [headV addSubview:moreBtn];
    
    return headV;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    PlayerViewController *goVC = [[PlayerViewController alloc]init];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    if (indexPath.row%2 == 1) {
        goVC.isVIP = YES;
    }else{
        goVC.isVIP = NO;
    }
    [self.navigationController pushViewController:goVC animated:YES];
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
